﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;

namespace XDA_ROM_Hub
{
    public partial class xrh_Backup : Form
    {
        public xrh_Backup()
        {
            InitializeComponent();
        }

        private void xrh_Backup_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            richTextBox1.Text += "Please wait, this will take up to 5min.";
            richTextBox1.Text += "Output log will be shown when finished.";
            Process p = new Process();
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.FileName = "XRH_Backup.bat";
            p.Start();
            string output = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            richTextBox1.Text = output;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure you are in recovery?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                richTextBox1.Text += "Please wait, this will take up to 5min.";
                richTextBox1.Text += "Output log will be shown when finished.";
                Process p = new Process();
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.FileName = "XRH_Restore.bat";
                p.Start();
                string output = p.StandardOutput.ReadToEnd();
                p.WaitForExit();
                richTextBox1.Text = output;
            }
            
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure you are in recovery?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                DialogResult results = MessageBox.Show("Click yes to restore Data, click no to restore System.", "Advance Restore", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
                if (results == DialogResult.Yes)
                {
                    richTextBox1.Text += "Please wait, this will take up to 5min.";
                    richTextBox1.Text += "Output log will be shown when finished.";
                    Process p = new Process();
                    p.StartInfo.UseShellExecute = false;
                    p.StartInfo.CreateNoWindow = true;
                    p.StartInfo.RedirectStandardOutput = true;
                    p.StartInfo.FileName = "XRH_Restore_Data.bat";
                    p.Start();
                    string output = p.StandardOutput.ReadToEnd();
                    p.WaitForExit();
                    richTextBox1.Text = output;
                }
                else if (results == DialogResult.No)
                {

                    richTextBox1.Text += "Please wait, this will take up to 5min.";
                    richTextBox1.Text += "Output log will be shown when finished.";
                    Process p = new Process();
                    p.StartInfo.UseShellExecute = false;
                    p.StartInfo.CreateNoWindow = true;
                    p.StartInfo.RedirectStandardOutput = true;
                    p.StartInfo.FileName = "XRH_Restore_System.bat";
                    p.Start();
                    string output = p.StandardOutput.ReadToEnd();
                    p.WaitForExit();
                    richTextBox1.Text = output;
                }
            }
        }
        private void button4_Click(object sender, EventArgs e)
        {

            richTextBox1.Text += "Please wait, this will take up to 10min.";
            richTextBox1.Text += "Output log will be shown when finished.";
            Process p = new Process();
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.FileName = "XRH_Pull.bat";
            p.Start();
            string output = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            richTextBox1.Text = output;
        }

        private void button5_Click(object sender, EventArgs e)
        {

            richTextBox1.Text += "Please wait, this will take up to 10min.";
            richTextBox1.Text += "Output log will be shown when finished.";
            Process p = new Process();
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.FileName = "XRH_Push.bat";
            p.Start();
            string output = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            richTextBox1.Text = output;
        }

        private void button6_Click(object sender, EventArgs e)
        {
            this.Hide();
        }
    }
}
